package com.chuzhiyun.chengguoxy.feature.internship.worktags;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.view.View;
import com.chuzhiyun.chengguoxy.R;
import com.chuzhiyun.chengguoxy.databinding.ActivityWorkTagsHomeBinding;
import com.chuzhiyun.chengguoxy.feature.base.BaseActivity;
import com.winton.bottomnavigationview.NavigationView;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;

@SuppressWarnings("ALL")
public class WorkTagsHomeActivity extends BaseActivity<ActivityWorkTagsHomeBinding> {
    @Override
    public void initView(View view) {
        // used for ViewPager adapter
        String tasksId = getIntent().getStringExtra("tasksId");
        String tasksName = getIntent().getStringExtra("tasksName");

        Bundle bundle = new Bundle();
        bundle.putString("tasksId",tasksId);
        bundle.putString("tasksName",tasksName);

        List<Fragment> fragments = new ArrayList<>(2);
        WorkTagsInfoFragment fragment0 = new WorkTagsInfoFragment();
        WorkTagsInputFragment fragment1 = new WorkTagsInputFragment();
        fragment0.setArguments(bundle);
        fragment1.setArguments(bundle);
        fragments.add(fragment0);
        fragments.add(fragment1);

        List<NavigationView.Model> tabs = new ArrayList<>();
        tabs.add(new NavigationView.Model.Builder(R.mipmap.worktags_select,R.mipmap.worktags_normal).title("详情").build());
        tabs.add(new NavigationView.Model.Builder(R.mipmap.work_tags_input_select,R.mipmap.work_tags_input_normal).title("提交").build());
        viewBinding.nv.setItems(tabs);
        viewBinding.nv.setOnTabSelectedListener(new NavigationView.OnTabSelectedListener() {
            @Override
            public void selected(int i, NavigationView.Model model) {
                viewBinding.vp.setCurrentItem(i);
            }

            @Override
            public void unselected(int i, NavigationView.Model model) {

            }
        });

        viewBinding.nv.build();
        viewBinding.nv.reminder(0,false,"");
        viewBinding.nv.reminder(1,false,"");

        VpAdapter mAdapter = new VpAdapter(getSupportFragmentManager(), fragments);
        viewBinding.vp.setAdapter(mAdapter);
        viewBinding.vp.setOffscreenPageLimit(3);
        viewBinding.vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                viewBinding.nv.check(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    public void initData() {

    }

    @Override
    public void setListener() {

    }

    @Override
    protected ActivityWorkTagsHomeBinding getViewBinding() {
        return ActivityWorkTagsHomeBinding.inflate(getLayoutInflater(), baseBinding.getRoot(), true);
    }

    private static class VpAdapter extends FragmentPagerAdapter {
        private final List<Fragment> data;
        VpAdapter(FragmentManager fm, List<Fragment> data) {
            super(fm);
            this.data = data;
        }

        @Override
        public int getCount() {
            return data.size();
        }

        @NotNull
        @Override
        public Fragment getItem(int position) {
            return data.get(position);
        }
    }

}